package com.erp.config;

import com.erp.mapper.LogMapper;
import com.erp.pojo.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Component
public class PathInterceptor implements HandlerInterceptor {

    @Autowired
    private LogMapper logMapper;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object name = request.getSession().getAttribute("name");
        if (name==null){
            System.out.println("拦截了："+request.getServletPath()+" 请求");
            logMapper.insert(new Log(0,"拦截了："+request.getServletPath()+" 请求",3,new Date(),17));
            return false;
        }else {
            return true;
        }
    }


}
